var app = getApp()
Page({
  data: {
    showCardCode:false,

  },

  onLoad: function (e) {
    var that = this;
    app.setNavtitle('卡包');
  },
  onShow:function(){
    var that = this;
    if (!app.globalData.plumSession) {
      console.log("暂未获取到session");
      app.wechatSq(that);
    } else {
      that.cardData();
      that.setData({
        isHasunionid: app.globalData.isHasunionid
      })
      // this.requestMemberCardList();
      // this.requestTimeCardList();
    }
  },
  //显示二维码
  openCardCode(){
    this.setData({
      showCardCode:true
    })
  },
  hideCardCode(){
    this.setData({
      showCardCode: false
    })
  },
  cardData: function () {
    var that = this;
    var courseId = that.data.courseId;
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_member_card_count',
      },
      success: function (res) {
        if (res.data.ec == 200) {
          console.log(res.data)
          var dataInfo = res.data.data;
          that.setData({
            card1Num: dataInfo.card1Num,
            card2Num: dataInfo.card2Num,
            card2Hadbuy: dataInfo.card2Hadbuy,
            card1Hadbuy: dataInfo.card1Hadbuy,
            vcmCard: dataInfo.vcmCard ? dataInfo.vcmCard:'',
            card1Info: dataInfo.card1Info,
            card2Info: dataInfo.card2Info,
          })
        } else {
          console.log(res.data)
        }
      },
      complete: function () {
        wx.hideLoading();
      }
    });
  },
  
  prevCard: function () {
    var that = this;
    var current = that.data.current;
    if (current == 0) {
      current = 1
    } else {
      current--;
    }
    console.log(current)
    that.setData({
      current: current
    });
  },
  nextCard: function () {
    var that = this;
    var current = that.data.current;
    if (current == 1) {
      current = 0
    } else {
      current++;
    }
    console.log(current)
    that.setData({
      current: current
    });
  },
  //打开已开卡详情
  toCardDetail(e){
    var type = e.currentTarget.dataset.type;
    if (type == 'count'){
      wx.navigateTo({
        url: '/subpages/storeMemberPage/storeMemberPage',
      })
    }else{
      wx.navigateTo({
        url: '/subpages/buyMenberCard/buyMenberCard',
      })
    }
    
  },
  //打开折扣卡列表
  openBuyMenberCard:function(){
    var that = this;
    wx.navigateTo({
      url: '/subpages/buyMenberCard/buyMenberCard',
    })
  },
  //打开优惠次卡列表
  openCardList:function(){
    var that = this;
    wx.navigateTo({
      
      url:'/subpages/cardList/cardList'
    })
  },
  getunionId: function (e) {
    var that = this;
    var userdata = e.detail;
    console.log(e.detail);
    app.getUnionid(that, userdata);
  },
  openSuccess:function(e){
    console.log(e);
  }  
})